package com.xiaoye.qbproject.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoye.qbproject.domain.BlbcWarfareExamplesRelation;
import com.xiaoye.qbproject.mapper.BlbcWarfareExamplesRelationMapper;
import com.xiaoye.qbproject.service.BlbcWarfareExamplesRelationService;
import com.xiaoye.qbproject.vo.BlbcWarfareExamplesRelationVo;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Administrator
 * @description 针对表【BLBC_WARFARE_EXAMPLES_RELATION(兵力编程编组 和 战例关系)】的数据库操作Service实现
 * @createDate 2025-01-02 12:05:44
 */
@Service
public class BlbcWarfareExamplesRelationServiceImpl extends ServiceImpl<BlbcWarfareExamplesRelationMapper, BlbcWarfareExamplesRelation>
        implements BlbcWarfareExamplesRelationService {
    /**
     * @param blbcWarfareExamplesRelationVo
     * @description: 设置兵力编程编组 与 战例的关系
     * @author: ChenYao
     * @return: void
     * @ceateDate: 2025-01-02 12:39
     */
    @Override
    public void setBlbcWarfareExamplesRelation(BlbcWarfareExamplesRelationVo blbcWarfareExamplesRelationVo) {
        if (blbcWarfareExamplesRelationVo == null) {
            return;
        }
        String blbcId = blbcWarfareExamplesRelationVo.getBlbcId();
        // 先删除之前的所有关系
        this.remove(new QueryWrapper<BlbcWarfareExamplesRelation>().eq("BLBC_ID", blbcId));
        if (blbcWarfareExamplesRelationVo.getWarfareExamplesIds() == null || blbcWarfareExamplesRelationVo.getWarfareExamplesIds().isEmpty()) {
            return;
        }
        // 再添加新的关系

        blbcWarfareExamplesRelationVo.getWarfareExamplesIds().forEach(warfareExampleId -> {
            BlbcWarfareExamplesRelation blbcWarfareExamplesRelation = new BlbcWarfareExamplesRelation();
            blbcWarfareExamplesRelation.setBlbcId(blbcId);
            blbcWarfareExamplesRelation.setText(blbcWarfareExamplesRelationVo.getText());
            blbcWarfareExamplesRelation.setWarfareExamplesId(warfareExampleId);
            this.save(blbcWarfareExamplesRelation);
        });
    }

    /**
     * @param blbcId
     * @description: 根据兵力编程编组id获取 兵力编程编组 与战例关系
     * @author: ChenYao
     * @return: java.util.List<com.xiaoye.qbproject.domain.BlbcWarfareExamplesRelation>
     * @ceateDate: 2025-01-02 13:02
     */
    @Override
    public List<BlbcWarfareExamplesRelation> getBlbcWarfareExamplesRelation(String blbcId) {
        return baseMapper.selectList(Wrappers.<BlbcWarfareExamplesRelation>lambdaQuery().eq(BlbcWarfareExamplesRelation::getBlbcId, blbcId));
    }
}




